home *** CD-ROM | disk | FTP | other *** search
- Path: news.pi.net!news
- From: janc@pop.pi.net (Jan Cornelis)
- Newsgroups: comp.lang.c++
- Subject: Trees !, Who can help me to improve my trees code ! <janc@pi.net>
- Date: Sun, 21 Jan 1996 02:23:26 GMT
- Organization: Planet Internet
- Message-ID: <4dr86i$75f@neptunus.pi.net>
- NNTP-Posting-Host: asd18.pi.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Who can help me with the following code written. The code doesn't work
- properly. I cannot understand why it doesn't work and how it should be
- improved. Is somebody there capable to help me out correcting this
- code ?
- Then i would like you to ask to help me either with a function in
- searching through the tree !
-
- My e-mail adress: janc@pi.net
-
- #include<stdio.h>
- class jc
- {
- public:
- jc()
- {
- tail=NULL;
- count = 0;
- }
-
- // This function should add a value to the tree !
- void addtree(int p);
-
- // This function should print one value from the tree one by one !
- void onefurther();
-
- private:
- struct list
- {
- // 'e' is the integer number for the tree !
- int e;
- // The left side of the tree
- list *left;
- // The right side of the tree
- list *right;
- };
-
- int count;
- list *tail;
- };
-
- void jc::addtree(int p)
- {
- if (tel==0)
- {
- tail = new list;
- tail->links=NULL;
- tail->rechts=NULL;
- tait=NULL;
- tail->e=p;
- tel++;
- }
- else
- {
- if (p < tail->e)
- {
- if (tail->left!=NULL)
- {
- tail->left = new list;
- tail = tail->left;
- }
- else
- {
- tail = tail-> right;
- }
- }
- else
- {
- if (tail->right != NULL)
- {
- tail->right = new list;
- tail = tail->right;
- }
- else
- {
- tail = tail->right;
- }
- }
- tail->left = NULL;
- tail->right = NULL;
- tail->e=p;
- }
- }
-
- void jc::onefurther()
- {
- tail = tail->left;
- printf("\nThe value = %i",tail->e);
- tail = tail->right;
- }
-
- void main()
- {
- jc a;
-
- for (int i=1;i <= 6;i++)
- a.addtail(i);
-
- for (int k=1;k <= 6;k++)
- a.onefurther();
- }
-
-
-